package cn.amebius.simpledocker.entity.po;

import cn.amebius.simpledocker.exception.DataErrorException;
import cn.hutool.core.date.DateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

import java.util.Date;

/**
 * 所有数据库的基础Po都有三个基本属性，id,deleted,create_time
 * @author 阿伟
 * @date 2023/7/27 16:31
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BasePo {

    @NonNull
    private Integer id;

    @NonNull
    private Date createTime;

    @NonNull
    private Integer deleted;

    public void setDel(){
        this.deleted = 1;
    }

    public void setNoDel() {
        this.deleted = 0;
    }

    /**
     * 返回Dao是否被删除
     * @return true：被删除   false：未被删除
     */
    public boolean isDeleted() {
        return this.deleted == 1;
    }

    public static void check(BasePo bp) {
        if (bp == null || bp.id.toString().isEmpty() || bp.createTime.toString().isEmpty() || bp.deleted.toString().isEmpty()) {
            throw new DataErrorException("数据异常:基本数据丢失");
        }
    }


}
